<?php

namespace app\advertisement\controller;

use app\common\controller\PCBase;
use app\advertisement\logic\AdvertisingLogic;
use app\advertisement\model\Advertising as AdvertisingModel;
use think\facade\Db;
use Throwable;
use app\common\library\Upload;

class Advertising extends PCBase
{
    /**
     * 模型
     * @var object
     * @phpstan-var AdvertisingModel
     */
    protected object $model;

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new AdvertisingModel();
    }

    /**
     * index
     * @throws Throwable
     */
    public function index()
    {
        $params     = $this->request->post();
        $AdvertisingLogic = new AdvertisingLogic();
        return $AdvertisingLogic->index($params);
    }

    /**
     * export
     * @throws Throwable
     */
    public function export()
    {
        $params     = $this->request->post();
        $AdvertisingLogic = new AdvertisingLogic();
        return $AdvertisingLogic->export($params);
    }

    /**
     * uploadAdv
     * @throws Throwable
     */
    public function uploadAdv()
    {
        $file       = $this->request->file('file');
        $upload     = new Upload($file);
        $attachment = $upload->upload(null, $this->getAdminId());
        $AdvertisingLogic = new AdvertisingLogic();
        $return     = $AdvertisingLogic->uploadAdv($attachment['url']);
        return  $this->jsonMessage(200, true, $return,null);
    }

}
